﻿
layui.use(['form', 'layer'], function () {
    var form = layui.form,
        layer = layui.layer;

    $(function () {
        loadList();
    });
});

//查询
function search() {
    var queryParams = {
        "s_0_PersonName|IDCard": $('#tbKey').val()
    };
    $.extend(true, _table.InitOptions.params, queryParams); //分页带查询参数
    _table.reload();
}

//初始化表格
function loadList() {
    _table.init({
        elem: '#table',
        url: 'Person.ashx',
        contentType: "application/x-www-form-urlencoded", /**支持跨域**/
        pageSize: 15, //单页记录数
        striped: false, //是否显示行间隔色
        checkboxHeader: true,
        singleSelect: false,
        onLoadSuccess: function (data) {
        },
        params: {
            PostType: 'list',
            ActionType: 'Person',
            rmd: Math.random()
        }
    });
}

//格式化序号
function formatterNum(value, row, index) {
    //获取每页显示的数量
    var pageSize = $('#table').bootstrapTable('getOptions').pageSize;
    //获取当前是第几页
    var pageNumber = $('#table').bootstrapTable('getOptions').pageNumber;
    //返回序号，注意index是从0开始的，所以要加上1
    return (pageSize * (pageNumber - 1) + index + 1);
}

//格式化人员头像
function formatterImageUrl(value, row, index) {
    if (value == null) {
        return '<img src="/resources/images/nopic.png" style="height:80px;width:80px;" />';
    } else {
        return '<img src="' + value + '"  style="height:80px;width:80px;" />';
    }
}

//格式化操作按钮
function formatterOperationMenu(value, row, index) {
    return app.getOperationMenu('GUID', row);
}

//新增
function add() {
    layer.open({
        title: "人员信息",
        type: 2,
        area: ["100%", "100%"],
        scrollbar: false,
        content: "PersonSet.aspx"
    });
}

//查看
function view(id) {
    layer.open({
        title: "人员信息",
        type: 2,
        area: ["100%", "100%"],
        scrollbar: false,
        content: "PersonView.aspx?GUID=" + id
    });
}

//编辑
function edit(id) {
    layer.open({
        title: "人员信息",
        type: 2,
        area: ["100%", "100%"],
        scrollbar: false,
        content: "PersonSet.aspx?GUID=" + id
    });
}

//删除
function del(id) {
    layer.confirm('确定删除?', {
        icon: 3,
        title: '提示'
    }, function (index) {
        app.del('Person.ashx', {
            ActionType: 'Person',
            GUID: id
        }, function (data) {
            layer.msg(data.msg);
            if (data.success) {
                search();
            }
        });
        layer.close(index);
    });
}

//导入
function importExcel() {
    layer.open({
        title: "人员信息导入",
        type: 2,
        area: ["100%", "100%"],
        scrollbar: false,
        content: "ImportPersonSet.aspx"
    });
}

//导出
function exportExcel() {
    var loading = layer.load(0);
    app.ajax('Person.ashx', {
        PostType: 'Export',
        ActionType: 'ExportPerson',
        "s_0_PersonName|IDCard": $('#tbKey').val()
    }, function (data) {
        layer.close(loading);
        if (data.success && data.text) {
            layer.msg('导出成功');
            $("#disExport").attr("href", data.text)[0].click();
        }
        else {
            layer.msg('导出失败');
        }
    });
}

//导出复杂表头
function exportExcel2() {
    var loading = layer.load(0);
    app.ajax('Person.ashx', {
        PostType: 'Export',
        ActionType: 'ExportPerson2',
        "s_0_PersonName|IDCard": $('#tbKey').val()
    }, function (data) {
        layer.close(loading);
        if (data.success && data.text) {
            layer.msg('导出成功');
            $("#disExport").attr("href", data.text)[0].click();
        }
        else {
            layer.msg('导出失败');
        }
    });
}

//导出Word
function exportWord(id) {
    var loading = layer.load(0);
    app.ajax('Person.ashx', {
        PostType: 'Export',
        ActionType: 'ExportPersonWord',
        GUID: id
    }, function (data) {
        layer.close(loading);
        if (data.success && data.text) {
            layer.msg('导出成功');
            $("#disExport").attr("href", data.text)[0].click();
        }
        else {
            layer.msg('导出失败');
        }
    });
}

//导出PDF
function exportPdf(id) {
    var loading = layer.load(0);
    app.ajax('Person.ashx', {
        PostType: 'Export',
        ActionType: 'ExportPersonPdf',
        GUID: id
    }, function (data) {
        layer.close(loading);
        if (data.success && data.text) {
            layer.msg('导出成功');
            $("#disExport").attr("href", data.text)[0].click();
        }
        else {
            layer.msg('导出失败');
        }
    });
}
